// pages/manage/withdrawal/withdrawal.js
var app=getApp();
var util=require('../../../utils/util');
var page_not;
var page_aly;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    scrollHev: '',
    search: '',
    tabs: [{
      title: "待处理",
      color: "orangered"
    }, {
      title: "已处理",
      color: ""
    }],
    activeIndex: 0,
    sliderOffset: 0,
    sliderLeft: 0,
    waitingList:[],
    successList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    // 获取系统信息
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          widheight: res.windowHeight,
          scrollHev: res.windowHeight - 50
        });
      }
    });
  },
  //tab菜单
  tabClick: function (e) {
    this.setData({
      sliderOffset: e.currentTarget.offsetLeft,
      activeIndex: e.currentTarget.id,
    });

    var tabs = this.data.tabs;
    for (let i = 0; i < 2; i++) {
      tabs[i].color = "black";
    }
    tabs[e.currentTarget.id].color = "orangered";
    this.setData({
      tabs: tabs
    })
  },
  seek_w(page){
    var that=this;
    wx.showLoading({
      title: '加载中',
    })
    util.request('/withdrawal',{
      status:"waiting",page:page
    },"GET").then(res=>{
      console.log(res)
      let data=res.data;
      wx.hideLoading({
        success: (res) => {},
      })
      that.setData({
        waitingList:that.data.waitingList.concat(data)
      })
    })
  },
  seek_s(page){
    var that=this;
    wx.showLoading({
      title: '加载中',
    })
    util.request('/withdrawal',{
      status:"success",page:page
    },"GET").then(res=>{
      console.log(res)
      let data=res.data;
      wx.hideLoading({
        success: (res) => {},
      })
      that.setData({
        successList:that.data.successList.concat(data)
      })
    })
  },
  toLookup:function(e){
    let mold=e.currentTarget.dataset.mold;
    let ind=e.currentTarget.dataset.index;
    var data;
    if(mold=='waiting'){
      data=JSON.stringify(this.data.waitingList[ind])
    }else{
      data=JSON.stringify(this.data.successList[ind])
    }
    wx.navigateTo({
      url: './lookup?data='+data,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this;
    page_not=1;
    page_aly=1;
    that.setData({
      waitingList:[],
      successList:[]
    })
    that.seek_w(page_not)
    that.seek_s(page_aly)
  },
  async bindDownLoad(e) {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    let mold=e.currentTarget.dataset.mold;
    if(mold=='waiting'){
      page_not=page_not+1;
      this.seek_w(page_not)
    }else{
      page_aly=page_aly+1;
      this.seek_s(page_aly)
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})